package com.class04.lambda;

import org.junit.jupiter.api.Test;

import java.util.Comparator;

/**
 * @ClassDescription:
 *
 *
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2023/11/28 15:01
 */
public class LambdaTest {
    @Test
    public void test1() {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("hello");
            }
        };
        runnable.run();
        System.out.println("==============================");
        Runnable r1 = () -> {
            System.out.println("hello2");
        };
        r1.run();
    }

    @Test
    public void test2() {
        Comparator<Integer> com1 = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(o1, o2);
            }
        };
//        compare() o1==o1  返回值0  | o1>o2  返回值1   |   o1<o2  返回值-1
        int compare = com1.compare(12, 12);
        System.out.println("compare = " + compare);
        System.out.println("============================");
//        2.lambda表达式
        Comparator<Integer> com2 = (Integer o1, Integer o2) -> {
            return Integer.compare(o1, o2);
        };
        int compare1 = com2.compare(21, 12);
        System.out.println("compare1 = " + compare1);
        System.out.println("============================");
        
        //方法引用
        Comparator<Integer> com3 = Integer::compare;
        int compare2 = com3.compare(12, 32);
        System.out.println("compare2 = " + compare2);
        


    }
}
